/**
 * 文件名称:  Constant.java
 * 文件序号:  序号
 * 内容描述:  文件简单描述，多行换行书写
 * 版权声明:  山东鸿蝶信息技术有限公司
 * 创建用户:  zhangkai
 * 创建日期:  2017/2/25 15:55
 * 修改用户:  无
 * 修改日期:  无
 * 修改说明:  无
 * 文件版本:  V1.0
 * 文件路径:
 */

package com.hongdee.crm;


import com.hongdee.common.util.StringUtil;
import com.hongdee.common.util.TokenUtil;

import java.net.Inet4Address;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 名  称:Constant
 * 类  型: class
 * 描  述: 用一句话描述类的作用
 * 路  径:com.hongdee.crm
 * 作  者:zhangkai
 * 日  期:2017/2/25 15:55
 */
public class Constant {

    public static enum SEEK_HELP{
        /*初始默认*/init,
        /*完成*/    complete
    }

    public static final String YYYYMMDD = "yyyy-MM-dd";

    public static enum DEF_STATUS {
        STOP, START
    }

    //流失返还
    public static final String LOST_RETURN = "2";
    //新车增长
    public static final String NEW_CAR = "1";
    //社会招揽
    public static final String SH_NEW = "3";

    //工单类型
    public static final String ORDER_TYPE_WX = "维修";
    public static final String ORDER_TYPE_SP = "索赔";
    /**
     * 车量流失默认月数
     */
    public static final int DEF_CAR_LOST_MONTH = 12;


    /*
    * 车辆分配类型
    * **/
    //全部
    public static final String CAR_ALL = "0";
    //尾号
    public static final String CAR_WH = "1";
    //尾数
    public static final String CAR_WS = "2";
    //Vin
    public static final String CAR_VIN = "3";

    public static class DISTCARTYPE {
        //全部
        public static final String CAR_ALL = "0";
        //尾号
        public static final String CAR_WH = "1";
        //尾数
        public static final String CAR_WS = "2";
        //Vin
        public static final String CAR_VIN = "3";
        // 车型
        public static final String CAR_CX = "4";
        //未分配
        public static final String CAR_WFP = "5";
    }

    //-------------任务相关-------------------------
    /**
     * 默认里程
     */
    public static final Integer DEF_MILE = 5000;

    /**
     * 任务权限
     */
    public static enum TASKPOWER {
        SEE, HANDLE
    }

    /**
     * 保险三种状态
     */
    public static class INSURANCE_TYPE {
        public static String NEW_INSURANCE = "新保";
        public static String RENEWAL = "续保";
        public static String RECEPTION = "接待";
    }

    /**
     * 与VIN分配进行匹配，天众公司除外
     *
     * @param sql
     * @param uid
     * @param byName
     */
    public static void VIN_TO_SQL(StringBuffer sql, String uid, String byName) {
        String companyId = TokenUtil.getCompanyId(uid);
        List<String> companys = new ArrayList<>();
        companys.add("8a1029015b612d40015b6142c2a50470");
        companys.add("ff8081815c820561015cc88e49834e0b");
        if (!companys.contains(companyId)) {
              /* 新规则，按车驾号分配车辆 */
            boolean flag = TokenUtil.isCompanyAdmin(uid);
            if (!flag) {
                sql.append(" AND EXISTS( select * from t_crm_car_ref_detail where " + byName + ".vin=vin and uid='" + uid + "' ) ");
            }
        }
//        if(!companyId.equals("8a1029015b612d40015b6142c2a50470")) {
//            /* 新规则，按车驾号分配车辆 */
//            boolean flag = TokenUtil.isCompanyAdmin(uid);
//            if (!flag) {
//                sql.append(" AND EXISTS( select * from t_crm_car_ref_detail where " + byName + ".vin=vin and uid='"+uid+"' ) ");
//            }
//        }
    }

    /**
     * 排除关闭提醒的客户信息
     *
     * @param sqlStr
     * @param pcode
     * @param code
     * @param byName
     */
    public static void REMIND_CLOSE_SQL(StringBuffer sqlStr, String pcode, String code, String byName) {
        sqlStr.append(" AND not EXISTS(select * from t_crm_car_remindclose cle where  " +
                "cle.vin=" + byName + ".vin and cle.type_code='" + code + "' and cle.type_pcode='" + pcode + "') ");
    }


    /* 个推相关配置信息 */
    public static String APPID = "3q0v6sesADAfsHatCNRNf5";
    public static String APPKEY = "CSwNnVids19OPguVcLY55";
    public static String MASTERSECRET = "piN9onxlMxAkS9nayCvLt1";
    public static String HOST = "http://sdk.open.api.igexin.com/apiex.htm";

    public static void main(String[] args) {
        List<String> companys = new ArrayList<>();
        companys.add("8a1029015b612d40015b6142c2a50470");
        if (companys.contains("8a1029015b612d40015b6142c2a50470")) {
            System.out.println("true");
        } else {
            System.out.println("false");
        }
    }

    //SA角色ID
    public static final String SA_ROLE_ID = "402881895bb23f8c015bb2427d500002";
    //客服专员
    public static final String KF_ROLE_ID = "402881895bb23f8c015bb243bfa5000a";
    //续保专员
    public static final String XB_ROLE_ID = "402881895bb23f8c015bb243286d0006";

    /**
     * 管理账套增加品牌、公司、区域过滤
     *
     * @param uid
     * @param companyId
     * @param area
     * @param brand
     * @param sqlBuffer
     * @param params
     * @param byName
     */
    public static void companyAndAreaAndBrand(String uid, String companyId, String area, String brand, StringBuffer sqlBuffer, List<Object> params, String byName) {
        List<Map<String, Object>> companyMaps = TokenUtil.getDataCompany(uid);
        if (!"".equals(byName)) {
            byName = byName + ".";
        }
        if (!"".equals(StringUtil.formatEmpty(companyId))) {
            sqlBuffer.append(" and " + byName + "id = ? ");
            params.add(StringUtil.formatNull(companyId));
        } else {
            sqlBuffer.append(" and " + byName + "id in( ");
            for (int i = 0; i < companyMaps.size(); i++) {
                sqlBuffer.append("?");
                Map infoMap = companyMaps.get(i);
                String id = String.valueOf(infoMap.get("id"));
                params.add(id);
                if (i < (companyMaps.size() - 1)) {
                    sqlBuffer.append(" , ");
                }
            }
            sqlBuffer.append(" ) ");
        }
        //区域
        if (!"".equals(StringUtil.formatEmpty(area))) {
            sqlBuffer.append(" and " + byName + "o_area=? ");
            params.add(StringUtil.formatEmpty(area));
        }
        //品牌
        if (!"".equals(StringUtil.formatEmpty(brand))) {
            sqlBuffer.append(" and " + byName + "o_car_brand=? ");
            params.add(StringUtil.formatEmpty(brand));
        }
    }

    public static Long ONE_DAY_MIC_SECOND = Long.valueOf(24 * 60 * 60 * 1000);

}
